﻿using HomagGroup.Base.UI;
using HomagGroup.Base.UI.Themes.Resources;
using HomagChina.Nesting.Views;
using Proxy;
using System.Collections.ObjectModel;
using static HomagChina.Nesting.ProcessResourceInternal;
using static HomagChina.Nesting.Router.Utility;
using Application = System.Windows.Application;
using localText = PropertiesLibarary.Properties.Resources;
using UserControl = System.Windows.Controls.UserControl;

namespace HomagChina.Nesting
{
    public class HomeRoute : NotifyPropertyChangedBase
    {
        private CommonHandle Handle_Common;
        private SearchInfoHandle Handle_Search;
        private static UserControl userC;
        private static HomeViewModel homeViewModel;

        public RouterItemDataModel HomeRouteModel { get; set; }

        public HomeRoute(MainWindowViewModel baseViewModel, bool isInit)
        {
            Handle_Common = new CommonHandle();
            Handle_Search = new SearchInfoHandle();
            if (isInit)
            {
                homeViewModel = (HomeViewModel)GetViewModelInstance("HomeViewModel");
                userC = (UserControl)GetUserControlInstance("Home");
            }
            Home home = userC as Home;
            homeViewModel.RequestScrollPositionSave += home.ViewModel_RequestScrollPositionSave;
            homeViewModel.RequestScrollPositionRestore += home.ViewModel_RequestScrollPositionRestore;
            HomeRouteModel = new RouterItemDataModel()
            {
                ID = "1",
                viewLabel = localText.Home,
                viewName = "Home",
                keepalive = true,
                viewModelName = "HomeViewModel",
                ViewModel = homeViewModel,
                userControl = userC,
                Image = GetIconBrush(Icon.Home),
                functionKeyBarItems = new ObservableCollection<FunctionKeyBarItemDataModel>
                {
                    new FunctionKeyBarItemDataModel() {
                        Header = localText.Exit,
                        Position = 12,
                        Icon = GetIconBrush(Icon.Close, ImageDecoration.Circle),
                        Command = new RelayCommand(() => { Application.Current.Shutdown(); })
                    },
                    //new FunctionKeyBarItemDataModel() {
                    //    Header = localText.Error_message, Position = 11, Icon = GetResourceBrush("ErrorMessages"),
                    //    Command = new RelayCommand(baseViewModel.NavigateToExecute),CommandParameter = "4"
                    //},
                    //new FunctionKeyBarItemDataModel() {
                    //    Header = localText.History, Position = 10, Icon = GetResourceBrush("history") ,
                    //    Command= new RelayCommand(baseViewModel.NavigateToExecute),CommandParameter = "7"
                    //},
                    new FunctionKeyBarItemDataModel() {
                        Header = localText.CopyInfo,
                        Position = 9,
                        Icon =GetIconBrush(Icon.Copy),
                        Command=new RelayCommand(homeViewModel.HandleOpenMprFile)
                    },
                    //new FunctionKeyBarItemDataModel() {
                    //    Header = localText.Statistics, Position = 8, Icon = GetResourceBrush("Statistics"),
                    //    Command= new RelayCommand(baseViewModel.NavigateToExecute),  CommandParameter = "6"
                    //},

                    new FunctionKeyBarItemDataModel() {
                        Header = localText.Action,
                        Position = 7,
                        Icon =GetIconBrush(Icon.Play,ImageDecoration.Box),
                        Command = new RelayCommand(homeViewModel.Action)
                    },
                    new FunctionKeyBarItemDataModel() {
                        Header = localText.Delete,
                        Position =6,
                        Icon =GetIconBrush(Icon.Stop,ImageDecoration.Box),
                        Command=new RelayCommand(homeViewModel.HandleCancelAllTasks)
                    },
                      new FunctionKeyBarItemDataModel() {
                        Header = localText.RemoveMpr,
                          Position =5,
                          Icon =GetIconBrush(Icon.Delete,ImageDecoration.Box),
                          Command=new RelayCommand(homeViewModel.RemoveMprCommand)
                    },
                    new FunctionKeyBarItemDataModel() {
                        Header = localText.PrintState,
                        Position = 4,
                        Icon =GetIconBrush(Icon.Printer,overlayIcon: OverlayIcon.Clock),
                         Command= new RelayCommand(homeViewModel.PrintState)
                    },
                    //new FunctionKeyBarItemDataModel() {
                    //    Header = localText.Settings,
                    //    Position = 2,
                    //    Icon= GetResourceBrush("Settings") ,
                    //    Command= new RelayCommand(baseViewModel.NavigateToExecute),
                    //    CommandParameter = "2"
                    //},
                    new FunctionKeyBarItemDataModel() {
                        Header = localText.Info,
                        Position = 1,
                        Icon = GetIconBrush(Icon.Information, imageDecoration: ImageDecoration.Circle),
                        Command = new RelayCommand(() => {
                            Handle_Common.OpenInformationCommand(Handle_Search.GetSystemInfoMation()); })
                    }
                }
            };
        }
    }
}